<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>系统登录</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
     
     <link rel="stylesheet" href="layui/css/layui.css">
     <link rel="stylesheet" href="css/style.css">
      <!--验证码-->
   <script language="javascript" type="text/javascript">
            var code;
            function createCode() {  //函数体
                code = "";
                var codeLength = 5; //验证码的长度
                var checkCode = document.getElementById("checkCode");
                var codeChars = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
                'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
                'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); //所有候选组成验证码的字符，当然也可以用中文的
                for (var i = 0; i < codeLength; i++)
                {
                    var charNum = Math.floor(Math.random() * 52);//设置随机产生
                    code += codeChars[charNum];
                }
                if (checkCode)
                {
                    checkCode.className = "code";
                    checkCode.innerHTML = code;
                }
            }        
         </script>
  </head>
  <style>
    /*验证码*/
.code
    {
          background-color: silver;
            font-family:Arial; /*设置字体*/
            font-style:initial;
             color:brown;
             font-size:20px;
             border:0;
              padding:2px 3px;
             letter-spacing:3px;
             font-weight:bolder;  
             width:81px;
             height:23px;      
             margin-left: 739px;
             margin-top: -35px;
 
    }
    a
    {
        text-decoration:none;
        font-size:12px;
        color:#288bc4;
        }
    a:hover
    {
       text-decoration:underline;
        }
       .yz{
         position: absolute;
          margin-left: 220px;
          margin-top:-10px;
        }
         
</style>
  <style>
	  body { 
	  
	  background-rept:no-repeat;background-size:100%;}
  
  	.dd{
  		float:left;
  		margin-left:-530px;
  	}
  </style>
  
  <body onload="createCode()" background="./images/1.jpg" class="">
		  <div class="page-container">
            <h1>登录</h1>
            <form action="" method="post">
                <input type="text" name="userid" id="userid" class="username" placeholder="用户名">
                <input type="password" name="pwd" id="pwd" class="password" placeholder="密码">
                <div class="dd">
		      		<div style="padding-left:400px;">
		      			<input id="YZ" name="yz" style="width:120px;"/><label>：验证</label>
		      		</div>
		      	  <div class="code" id="checkCode" onclick="createCode()"></div>
		      	
		      	</div>
		      	<div class="layui-form-item input-item layui-input-active">
					<span style="font-family: STSong;color: red;" id="showinput"></span>
				</div>
                <button type="button" id="btnLogin">登录</button>
                <div class="error"><span>+</span></div>
            </form>

            <div class="connect"></div>
            <div align="center">系统权限管理<a id="OK" href="register.jsp" target="_blank" onclick="GetDom()" title="">注册</a></div>
        </div>
		
	
	</body>
	<script src="./js/jquery-3.3.1.js"></script>
	<script src="./layui/layui.all.js"></script>
	<script type="text/javascript" src="js/md5.js"></script>
	<script type="text/javascript" src="js/systempublickey.js"></script>
	<script>
		layui.use(['form','layer','jquery'], function(){
			var form = layui.form
			var layer = layui.layer
			var $ = layui.jquery
			
			$("#btnLogin").click(function(){
				var userid = $("#userid").val();
				var pwd = $("#pwd").val();
				var yz = $("#YZ").val();
				var YZ = yz.toUpperCase();
				var YZs = code.toUpperCase();
				
				/* 用MD5将密码做加密处理 */
				var enpwd = hex_md5(fix(userid,pwd));
				$("#pwd").val(enpwd);
				var param = '?userid='+userid+'&pwd='+enpwd;//参数组合
				//alert(enpwd);
				
				if(userid==null || userid=="" || userid==undefined){
					$("#userid").focus("");
					return;
				}else if(pwd==null || pwd=="" || pwd==undefined){
					$("#pwd").focus();
					return;
				}else if(pwd.length<6 || pwd.length>18){
					layer.alert('密码长度不符合规范!', {icon: 2});
					return;
				}else if(YZ==""){
					alert("验证码不能为空！");
		            createCode();//输错一次或提交一次都将会刷新一次验证码
		            return; //结束本次会话
				}else if(YZ!=code.toUpperCase()){
					alert("您输入的验证码有误，请重新输入！！");
		            createCode();//读取文件
		            return; //结束本次会话
				}
				
				$.ajax({
					type : 'get',
					url : 'user/userlogin',
					data:{
						userid:userid,
						pwd:enpwd
					},
					datatype : 'json',
					success : function(data) {
						if(data.code == 10001){
							document.getElementById("showinput").innerText = data.msg;
							setTimeout("javascript:location.href='frame.jsp'", 0);
						}else{
							layer.close(index);
							document.getElementById("showinput").innerText = data.msg;
						}
					},
					error:function(){
						document.getElementById("showinput").innerText = data.msg;
		   	        }
				});
			})
		})
		
		<!--验证码数据校验-->
		/*  function GetDom(){
		    if(document.getElementById("YZ").value==""){
		            alert("验证码不能为空！");
		            createCode();//输错一次或提交一次都将会刷新一次验证码
		            return false; //结束本次会话
		          }else if(document.getElementById("YZ").value.toUpperCase()!=code.toUpperCase()){ //toUpperCase不区分大小写
		            alert("您输入的验证码有误，请重新输入！！");
		            createCode();//读取文件
		          }                  
		      else{
		            return;
		        }
		  }  */
	</script>
	
</html>
